package com.example.netchat;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class JoinRoomServlet extends HttpServlet {
	private static final long serialVersionUID = 2369946491921606000L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String regId = req.getParameter("regId");
		String roomId = req.getParameter("roomId");
		
		if (req.getRequestURI().equalsIgnoreCase("/rooms/leave")) {
			Datastore.leaveRoom(Long.parseLong(roomId), regId);
		} else if (req.getRequestURI().equalsIgnoreCase("/rooms/join")) {
			Datastore.joinRoom(Long.parseLong(roomId), regId);
		}
	}
}
